//
//  ZJSCQusetModuleView.m
//  LovingPartyBuilding
//
//  Created by ZJ on 2017/5/4.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "ZJSCQusetModuleView.h"
#import "ZJSCQusetTopicView.h"
#import "ZJSCQusetOptionView.h"
#define VIEW_TAG 666
@interface ZJSCQusetModuleView ()<ZJSCQusetOptionViewDelegate>
{
    NSInteger _selectIndex;/**< 单选是使用   记录上次选中的 */
}
/** 单选 */
@property (nonatomic, strong) NSDictionary *dict;
/** 多选 */
@property (nonatomic, strong) NSMutableArray *dataArray;
/** 是否是多选 */
@property (nonatomic, assign) BOOL isMoreSelect;
@end

@implementation ZJSCQusetModuleView

- (instancetype)initWithFrame:(CGRect)frame isMoreSelect:(BOOL)isMoreSelect
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor viewBGGrayColor];
        self.isMoreSelect = isMoreSelect;
    }
    return self;
}


- (void)updateUI{
    CGFloat ViewBootm = 0;
    ZJSCQusetTopicView *tapicView = [[ZJSCQusetTopicView alloc] initWithFrame:CGRectMake(0, 0, self.width, 10)];
    [self addSubview:tapicView];
    tapicView.string = @"这是问题快来回答！！！！！！";
    NSArray *array = @[@"这是问题快来回答！！！！！！",@"这是问题快来回答！！！！！！这是问题快来回答！！！！！！这是问题快来回答！！！！！！这是问题快来回答！！！！！！",@"这是问题快来回答！！！！！！",@"这是问题快来回答！！！！！！这是问题快来回答！！！！！！"];
    ViewBootm = tapicView.bottom + 1;
    for (int i = 0; i < array.count ; i ++) {
        ZJSCQusetOptionView *OptionView = [[ZJSCQusetOptionView alloc]initWithFrame:CGRectMake(0, ViewBootm, self.width, 1)];
        OptionView.string = array[i];
        OptionView.tag = VIEW_TAG + i;
        OptionView.delegate = self;
        [self addSubview:OptionView];
        ViewBootm = OptionView.bottom + 1;
        self.height = ViewBootm + 8 * [UIScreen zj_screenHScale];
    }
    

}

#pragma mark - ZJSCQusetOptionViewDelegate 协议方法
- (void)ZJSCQusetOptionViewDelegate_selectClick:(ZJSCQusetOptionView *)View{
    if (self.isMoreSelect) {//多选
        if (View.isSelect) {//选中
//            [self.dataArray addObject:<#(nonnull id)#>]
        }else{
//        [self.dataArray removeObject:<#(nonnull id)#>]
        }
        
        if ([self.delegate respondsToSelector:@selector(ZJSCQusetModuleViewDelegate_MoreSelectToDataArray:) ]) {
            [self.delegate ZJSCQusetModuleViewDelegate_MoreSelectToDataArray:self.dataArray];
        }
        
}else{//单选
        if (View.isSelect) {//选中
            if (_selectIndex != 0) {
                ZJSCQusetOptionView *oldView = [self viewWithTag:_selectIndex];
                oldView.isSelect = NO;
            }
            _selectIndex = View.tag;
//            self.dict = ;
        }else{//取消选中
            _selectIndex = 0;
            self.dict = nil;
        }
    }
    
    if ([self.delegate respondsToSelector:@selector(ZJSCQusetModuleViewDelegate_MoreSelectToDict:) ]) {
        [self.delegate ZJSCQusetModuleViewDelegate_MoreSelectToDict:self.dict];
    }
    
}


#pragma mark - Setter


#pragma mark - Getters
- (NSMutableArray *)dataArray{
    if (_dataArray == nil){
        _dataArray = [NSMutableArray array];
        
    }
    return _dataArray;
}

@end
